package cn.kai.basic.util;

import cn.kai.basic.jwt.*;
import cn.kai.user.domain.Logininfo;
import lombok.extern.slf4j.Slf4j;
import javax.servlet.http.HttpServletRequest;
import java.security.PublicKey;
@Slf4j
public class LogContext {

    public static Logininfo getLogininfo(HttpServletRequest request){
        try{
            String token = request.getHeader("token");
            PublicKey publicKey = RsaUtils.getPublicKey(JwtRasHolder.INSTANCE.getJwtRsaPubData());
            Payload<UserInfo> payload = JwtUtils.getInfoFromToken(token, publicKey, UserInfo.class);
            UserInfo userInfo = payload.getUserInfo();
            if (userInfo == null){
                log.error("用户未登录!");
                return null;
            }
            return userInfo.getLogininfo();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    public static void getLogininfo() {
    }
}
